package de.baumann.browser.api.net.util;

import java.math.BigDecimal;
import java.util.List;

import de.baumann.browser.api.net.OrderApiService;
import de.baumann.browser.api.net.base.ApiBuilder;
import de.baumann.browser.api.net.vo.Order;
import de.baumann.browser.api.net.vo.PayParam;
import de.baumann.browser.api.net.vo.Result;
import io.reactivex.Observable;

/**
 * @author:
 * @date:2019/1/7 11:47
 * @discription: 订单相关接口 工具类
 */

public class OrderHttpUtil {

    private static OrderApiService orderApiService;

    static {
        orderApiService = ApiBuilder.buildService(OrderApiService.class);
    }


    /**
     * 创建算力包订单
     *
     * @param payMode 支付方式 7 ODIN  1 微信
     * @param count   数量
     * @param price   单价
     * @param amount  总价
     * @param id      算礼包ID
     */
    public static Observable<Result<PayParam>> createHashOrder(int payMode, int count, BigDecimal price, BigDecimal amount, String id) {
        return orderApiService.crateOrder("2", payMode, count, price.toString(), amount.toString(), id, "", "", "");
    }

    /**
     * ODIN 支付
     *
     * @param tradeNo  交易码
     * @param password 密码
     * @return
     */
    public static Observable<Result<PayParam>> odinPay(String tradeNo, String password) {
        return orderApiService.odinPay(tradeNo, password);
    }

    /**
     * 取消订单
     *
     * @param tradeNo
     * @return
     */
    public static Observable<Result> cancelOrder(String tradeNo) {
        return orderApiService.cancelOrder(tradeNo);
    }

    /**
     * 获取所有订单
     *
     * @return Observable
     */
    public static Observable<Result<List<Order>>> getOrders(int type, int status, int pageNum) {
        return orderApiService.getOrders(type, status, pageNum, 100);
    }


}
